package com.ceba.test.modules.signvisual.logicService;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.ceba.base.utils.IDSFileUtils;
import com.ceba.base.utils.PDFUtils;
import com.ceba.base.web.response.IResult;
import com.ceba.test.base.config.LogicPathUtil;
import com.ceba.test.modules.storage.logicService.StorageFileCacheManage;
import org.apache.commons.collections.CollectionUtils;
import org.json.JSONArray;

import com.ceba.test.base.configs.CebaPathUtil;
import com.ceba.test.base.entity.SignPrintPDF;
import com.ceba.test.base.enums.EditionTypeEnum;
import com.ceba.test.base.web.UserUtils;
import com.ceba.test.modules.admin.entity.GStamp;
import com.ceba.test.modules.sign.logicService.SignLogicService;
import com.ceba.test.modules.signvisual.logicService.abstracts.SignVisualAbstract;
import com.ceba.test.modules.statistic.entity.ReportSign;

import configs.context.SpringBeans;

public class SignVisualLogicAbstractAllService extends SignVisualAbstract{
	
	private SignLogicService signLogicService = SpringBeans.getSignLogicService("signLogicService");
	/**
	 * 盖章
	 * @param signPrintPDFList 用户章 信息
	 * @param pdfPath 盖章报告
	 * @return 盖章后生成的报告路径 --临时路径
	 */
	@Override
	public String seal(List<SignPrintPDF> signPrintPDFList, String pdfPath,String outPdfPath) throws Exception {
		if(CollectionUtils.isEmpty(signPrintPDFList)){return null;}
		String outPath= LogicPathUtil.getPhysicalTempFolder(StorageFileCacheManage.getSystemUseAddressId())+"outSeal"+File.separator;
		IDSFileUtils.createDir(outPath);
		signPrintPDFToIdG_Stamp(signPrintPDFList);
		List<GStamp> g_StampList=signPrintPDFToG_Stamp(signPrintPDFList);
		outPath=outPath+new File(pdfPath).getName();
		boolean bool= PDFUtils.insertImagesByMatchNameOrXY( pdfPath,outPath,new JSONArray(g_StampList));
		if(!bool){
			return null;
		}
		return outPath;
	}
	/**
	 * 签名
	 * @param signPrintPDFList 用户章 信息
	 * @param pdfPath 签名报告
	 * @return 签名后生成的报告路径 --临时路径
	 */
	@Override
	public String autograph(List<SignPrintPDF> signPrintPDFList, String pdfPath,String outPdfPath,ReportSign parm) throws Exception {
		String outPath=LogicPathUtil.getPhysicalTempFolder(StorageFileCacheManage.getSystemUseAddressId())+"outAutograph"+File.separator;
		IDSFileUtils.createDir(outPath);
		signPrintPDFToIdG_Stamp(signPrintPDFList);
		List<GStamp> g_StampList=signPrintPDFToG_Stamp(signPrintPDFList);
		IResult result = new IResult(true);
		List<GStamp> stamps = new ArrayList<GStamp>();
		stamps.add(g_StampList.get(0));
		signLogicService.signPdf( pdfPath,outPath,stamps,result,parm);
		if(result.getResult()){
			pdfPath=result.getString("filePath");
		}
		return outPath;
	}

}
